package ym.controller.front.house;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ym.pojo.Appointment;
import ym.service.AppointmentService;
import ym.vo.BaseResult;

import java.util.List;

/**
 * 预约
 */
@CrossOrigin
@RestController
@RequestMapping("/front/appointment")
public class FrontAppointmentCon {
    @Autowired
    private AppointmentService appointmentService;

    /**
     * 新增预约【时间为数字】
     *
     * @param appointment
     * @return
     */
    @PostMapping("/addNumber")
    public BaseResult addNumber(Appointment appointment) {
        appointmentService.addNumber(appointment);
        return BaseResult.ok();
    }
    /**
     * 新增预约【时间为字符串】
     *
     * @param appointment
     * @return
     */
    @PostMapping("/addString")
    public BaseResult addString(Appointment appointment) {
        appointmentService.addString(appointment);
        return BaseResult.ok();
    }

    /**
     * 取消预约
     *
     * @param appointmentId
     * @return
     */
    @DeleteMapping("/delete")
    public BaseResult delete(Integer appointmentId) {
        appointmentService.delete(appointmentId);
        return BaseResult.ok();
    }

    /**
     * 根据id查询预约【封装用户和房源】
     *
     * @param appointmentId
     * @return
     */
    @GetMapping("/findById")
    public BaseResult findById(Integer appointmentId) {
        Appointment appointment = appointmentService.findById(appointmentId);
        return BaseResult.ok(appointment);
    }

    /**
     * 根据用户查询所有预约【封装用户和房源】
     *
     * @param userId
     * @return
     */
    @GetMapping("/findAllByUserId")
    public BaseResult findAllByUserId(Integer userId) {
        List<Appointment> appointmentList = appointmentService.findAllByUserId(userId);
        return BaseResult.ok(appointmentList);
    }
}
